package com.java2207.group1.controller;

import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.common.R;
import com.java2207.group1.pojo.Entertainment;
import com.java2207.group1.service.EntertainmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/entertainment")
public class EntertainmentController {

    @Autowired
    private EntertainmentService entertainmentService;

    // 查询、分页
    @RequestMapping("/entertainmentList")
    public LayuiPageVo<Entertainment> entertainmentPageData(@RequestParam Map<String, Object> params){
        return entertainmentService.entertainmentPageData(params);
    }

    // 添加文娱项目信息
    @RequestMapping("/addEntertainment")
    public R addEntertainment(Entertainment entertainment){
        int i = entertainmentService.addEntertainment(entertainment);

        if (i == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    // 根据 id 删除文娱项目信息
    @RequestMapping("/deleteEntertainment")
    public R deleteEntertainment(int id){
        System.out.println(id);
        int i = entertainmentService.deleteEntertainment(id);
        if (i == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    // 修改文娱项目表的信息
    @RequestMapping("/updateEntertainment")
    public R updateEntertainment(Entertainment entertainment){
        int i = entertainmentService.updateEntertainment(entertainment);
        if (i == 1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @GetMapping("/batchEntertainment")
    public R batchEntertainment(String ids){
        int i = entertainmentService.batchEntertainment(ids);
        if (i > 0){
            return R.ok();
        }else {
            return R.error();
        }
    }

}
